<template>
    <div>
        <Modal v-model="modal.add" title="添加" :mask-closable="false" @on-visible-change="changeModalVisibleResetForm('addForm', $event)" width="1020">
            <Form ref="addForm" :model="form" :label-width="120" :rules="validateRules">
                <Row>
	<i-col span="12">
	<FormItem label="快递费模板标题" prop="title">
	<Input v-model="form.title" placeholder="请输入快递费模板标题" clearable/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="发货地" prop="expressPlace">
	<Input v-model="form.expressPlace" placeholder="请输入发货地" clearable/>
</FormItem>
	</i-col>

	<i-col span="12">
		<FormItem label="是否包邮" prop="expressFree">
		    
		        <Select v-model="form.expressFree" placeholder="是否包邮" filterable clearable>
		          <Option
		            v-for="(option, index) in expressFreeSelect"
		            :value="option.value"
		            :key="index"
		          >{{option.displayValue}}</Option>
		        </Select>
		    
		</FormItem>
	
	</i-col><i-col span="12">
	<FormItem label="计价方式" prop="valuationType">
	    
	        <Select v-model="form.valuationType" placeholder="计价方式" filterable clearable>
	          <Option
	            v-for="(option, index) in valuationTypeSelect"
	            :value="option.value"
	            :key="index"
	          >{{option.displayValue}}</Option>
	        </Select>
	    
	</FormItem>
	
	</i-col>

	<i-col span="12">
	<FormItem label="默认快递费" prop="defaultFee">
	<InputNumber v-model="form.defaultFee" placeholder="请输入默认快递费" style="width: 100%;"/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="默认规格" prop="defaultSpec">
	<InputNumber v-model="form.defaultSpec" placeholder="请输入默认规格" style="width: 100%;"/>
</FormItem>
	</i-col>

	<i-col span="12">
	<FormItem label="默认递增规格" prop="defaultIncrementSpec">
	<InputNumber v-model="form.defaultIncrementSpec" placeholder="请输入默认递增规格" style="width: 100%;"/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="默认递增快递费" prop="defaultIncrementFee">
	<InputNumber v-model="form.defaultIncrementFee" placeholder="请输入默认递增快递费" style="width: 100%;"/>
</FormItem>
	</i-col>

	<i-col span="12">
	<FormItem label="默认包邮条件" prop="defaultFreeCondition">
	<InputNumber v-model="form.defaultFreeCondition" placeholder="请输入默认包邮条件" style="width: 100%;"/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="默认包邮金额" prop="defaultFreeMaxPayment">
	<InputNumber v-model="form.defaultFreeMaxPayment" placeholder="请输入默认包邮金额" style="width: 100%;"/>
</FormItem>
	</i-col>

	<i-col span="12">
	<FormItem label="快递费模板说明" prop="description">
	<Input v-model="form.description" placeholder="请输入快递费模板说明" clearable/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="是否默认" prop="isDefault">
	    
	        <Select v-model="form.isDefault" placeholder="是否默认" filterable clearable>
	          <Option
	            v-for="(option, index) in isDefaultSelect"
	            :value="option.value"
	            :key="index"
	          >{{option.displayValue}}</Option>
	        </Select>
	    
	</FormItem>
	
	</i-col>
</Row>

            </Form>
            <div slot="footer">
                <Button type="text" size="large" @click="resetFormCancelModal('addForm', 'add')">取消</Button>
                <Button type="primary" size="large" @click="add" :loading="loading.add">添加</Button>
            </div>
        </Modal>
        <Modal v-model="modal.edit" title="修改" :mask-closable="false" @on-visible-change="changeModalVisibleResetForm('editForm', $event)" width="1020">
            <Form ref="editForm" :model="form" :label-width="120" :rules="validateRules">
                <Row>
	<i-col span="12">
	<FormItem label="快递费模板标题" prop="title">
	<Input v-model="form.title" placeholder="请输入快递费模板标题" clearable/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="发货地" prop="expressPlace">
	<Input v-model="form.expressPlace" placeholder="请输入发货地" clearable/>
</FormItem>
	</i-col>

	<i-col span="12">
	<FormItem label="是否包邮" prop="expressFree">
	    
	        <Select v-model="form.expressFree" placeholder="是否包邮" filterable clearable>
	          <Option
	            v-for="(option, index) in expressFreeSelect"
	            :value="option.value"
	            :key="index"
	          >{{option.displayValue}}</Option>
	        </Select>
	    
	</FormItem>
	</i-col><i-col span="12">
	
<FormItem label="计价方式" prop="valuationType">
	    
	        <Select v-model="form.valuationType" placeholder="计价方式" filterable clearable>
	          <Option
	            v-for="(option, index) in valuationTypeSelect"
	            :value="option.value"
	            :key="index"
	          >{{option.displayValue}}</Option>
	        </Select>
	    
	</FormItem>
	</i-col>

	<i-col span="12">
	<FormItem label="默认快递费" prop="defaultFee">
	<InputNumber v-model="form.defaultFee" placeholder="请输入默认快递费" style="width: 100%;"/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="默认规格" prop="defaultSpec">
	<InputNumber v-model="form.defaultSpec" placeholder="请输入默认规格" style="width: 100%;"/>
</FormItem>
	</i-col>

	<i-col span="12">
	<FormItem label="默认递增规格" prop="defaultIncrementSpec">
	<InputNumber v-model="form.defaultIncrementSpec" placeholder="请输入默认递增规格" style="width: 100%;"/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="默认递增快递费" prop="defaultIncrementFee">
	<InputNumber v-model="form.defaultIncrementFee" placeholder="请输入默认递增快递费" style="width: 100%;"/>
</FormItem>
	</i-col>

	<i-col span="12">
	<FormItem label="默认包邮条件" prop="defaultFreeCondition">
	<InputNumber v-model="form.defaultFreeCondition" placeholder="请输入默认包邮条件" style="width: 100%;"/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="默认包邮金额" prop="defaultFreeMaxPayment">
	<InputNumber v-model="form.defaultFreeMaxPayment" placeholder="请输入默认包邮金额" style="width: 100%;"/>
</FormItem>
	</i-col>

	<i-col span="12">
	<FormItem label="快递费模板说明" prop="description">
	<Input v-model="form.description" placeholder="请输入快递费模板说明" clearable/>
</FormItem>
	</i-col><i-col span="12">
	<FormItem label="是否默认" prop="isDefault">
	    
	        <Select v-model="form.isDefault" placeholder="是否默认" filterable clearable>
	          <Option
	            v-for="(option, index) in isDefaultSelect"
	            :value="option.value"
	            :key="index"
	          >{{option.displayValue}}</Option>
	        </Select>
	    
	</FormItem>
	</i-col>
</Row>

            </Form>
            <div slot="footer">
                <Button type="text" size="large" @click="resetFormCancelModal('editForm', 'edit')">取消</Button>
                <Button type="primary" size="large" @click="edit" :loading="loading.edit">修改</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
	import * as utils from '@/api/utils-v2'
	import * as ResponseStatus from '@/api/response-status'
    export default {
        name: 'ExpressTemplateAddEdit',
        data() {
            return {
                modal: {
                    add: false,
                    edit: false
                },
                loading: {
                    add: false,
                    edit: false
                },
				dataDictCodes: ['EXPRESS_FREE','EXPRESS_SPEC','EXPRESS_IS_DEFAULT'],
				dataDictItems: {},
				expressFreeSelect:[],
				valuationTypeSelect:[],
				isDefaultSelect:[],
                urls: {
                    addUrl: '/express-template/admin/save',
                    batchAddUrl: '/express-template/admin/batch-save',
                    editUrl: '/express-template/admin/update',
                    batchEditUrl: '/express-template/admin/batch-update'
                },
                form: {
                    title: null,
expressPlace: null,
expressFree: null,
valuationType: null,
defaultFee: null,
defaultSpec: null,
defaultIncrementSpec: null,
defaultIncrementFee: null,
defaultFreeCondition: null,
defaultFreeMaxPayment: null,
description: null,
isDefault: null,

                },
                validateRules: {
                    title: [
{type: 'string', required: true, message: '此项为必须项', trigger: 'blur'},
{type: 'string', min: 1, max: 50, message: '必须1-50个字符', trigger: 'blur'}
],
expressPlace: [
{type: 'string', required: true, message: '此项为必须项', trigger: 'blur'},
{type: 'string', min: 1, max: 50, message: '必须1-50个字符', trigger: 'blur'}
],
expressFree: [
{type: 'integer', required: true, message: '此项为必须项', trigger: 'blur, change'}
],
defaultFee: [
{type: 'number', required: true, message: '此项为必须项', trigger: 'blur, change'}
],
defaultSpec: [
{type: 'number', required: true, message: '此项为必须项', trigger: 'blur, change'}
],
description: [
{type: 'string', min: 1, max: 500, message: '必须1-500个字符', trigger: 'blur'}
],

                }
            }
        },
        computed: {},
        mounted() {
			            utils.getDataDict(this.dataDictCodes).then(response => {
			              if (response) {
			                this.dataDictItems = response
			                utils.getSelectDictItems(this, 'EXPRESS_FREE', 'expressFree', 'expressFreeSelect')
							utils.getSelectDictItems(this, 'EXPRESS_SPEC', 'valuationType', 'valuationTypeSelect')
						    utils.getSelectDictItems(this, 'EXPRESS_IS_DEFAULT', 'isDefault', 'isDefaultSelect')
			              }
			            }).catch(error => {
			              console.log(error)
			            })
		},
        methods: {
            changeModalVisibleResetForm(formRef, visible) {
                if (!visible) {
					this.$refs[formRef].resetFields()
					this.form.id = null
                }
            },
            resetFormCancelModal(formRef, modal) {
                this.modal[modal] = false
			    this.$refs[formRef].resetFields()
				this.form.id = null
            },
            add() {
                this.$emit('add')
            },
            edit() {
                this.$emit('edit')
            }
        }
    }
</script>

<style>
</style>
